package com.asset.troubleticket.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.asset.troubleticket.domain.Contact;
@Repository
public class ContactDao {
	@Autowired
	SessionFactory sessionFactory;
	
	
	public void addContact(Contact contact){
		try{
			sessionFactory.getCurrentSession().save(contact);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	
	public void editContact(Contact contact){
		try{
			sessionFactory.getCurrentSession().saveOrUpdate(contact);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public void deleteContact(Contact contact){
		try{
			sessionFactory.getCurrentSession().delete(contact);
			}catch(Exception ex){
				ex.printStackTrace();
			}
	}
	
	public Contact getById(Integer id){
		try{
		return (Contact)	sessionFactory.getCurrentSession().load(Contact.class,id);
			}catch(Exception ex){
				ex.printStackTrace();
				return null;
			}
	}
}
